package com.studyshare.util;

import java.util.List;

import com.example.studyshare.R;
import com.studyshare.model.Message;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CommSendViewAdapter extends ArrayAdapter<Message>{
    private List<Message> entries;
    private Activity activity;

    public CommSendViewAdapter(Activity a, int textViewResourceId, List<Message> messages) {
        super(a, textViewResourceId, messages);
        this.setEntries(messages);
        this.activity = a;
    }

    public static class ViewHolder{
        private TextView item1;
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ViewHolder holder;
        if (v == null) {
            LayoutInflater vi =
                    (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.fragment_comm_envoi, null);
            holder = new ViewHolder();
            holder.item1 = (TextView) v.findViewById(R.id.conversationslist);
            v.setTag(holder);
        }
        else{
            holder=(ViewHolder)v.getTag();
        }

        final Message message = getEntries().get(position);
        if (message != null) {
            holder.item1.setText( message.getMessage());
        }
        return v;
    }

    public List<Message> getEntries() {
        return entries;
    }

    public void setEntries(List<Message> entries) {
        this.entries = entries;
        this.notifyDataSetChanged();
    }
}